//
//  ByDocumentaryListCell.m
//  caipiao_ios
//
//  Created by mc on 2018/7/30.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDocumentaryListCell.h"

@implementation ByDocumentaryListCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByDocumentaryListCell";
    ByDocumentaryListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        [self initViews];
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UILabel *line = [[UILabel alloc] init];
    [self.contentView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(0);
        make.right.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(0);
        make.height.mas_equalTo(@1);
    }];
    line.backgroundColor = BY_LINE_COLOR;
    
    
    
    UILabel *numberLabel = [[UILabel alloc] init];
    [self.contentView addSubview:numberLabel];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.centerY.equalTo(self.contentView).offset(0);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    numberLabel.textAlignment = NSTextAlignmentCenter;
    numberLabel.textColor = [UIColor blackColor];
    numberLabel.font = FONT(14);
    self.numberLabel = numberLabel;
    
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(numberLabel.mas_right).offset(10);
        make.centerY.equalTo(self.contentView).offset(0);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    iconView.layer.cornerRadius = 25;
    iconView.layer.masksToBounds = YES;
    self.iconView = iconView;
    
    UIImageView *topView = [[UIImageView alloc] init];
    [self.contentView addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_left).offset(0);
        make.top.equalTo(self.contentView).offset(5);
        make.size.mas_equalTo(CGSizeMake(20, 18));
    }];
    topView.image = [UIImage imageNamed:@"guanjun皇冠上1"];
    self.topView = topView;
    
    UIImageView *bottomView = [[UIImageView alloc] init];
    [self.contentView addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_left).offset(0);
        make.right.equalTo(iconView.mas_right).offset(0);
        make.bottom.equalTo(iconView.mas_bottom).offset(-5);
        make.height.mas_equalTo(@20);
    }];
    bottomView.image = [UIImage imageNamed:@"guanjun皇冠下1"];
    self.bottomView = bottomView;
    
    UILabel *nickLabel = [[UILabel alloc] init];
    [self.contentView addSubview:nickLabel];
    [nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconView.mas_right).offset(10);
        make.top.equalTo(iconView.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(70, 20));
    }];
    nickLabel.text = @"翻滚的咸鱼";
    nickLabel.textColor = [UIColor blackColor];
    nickLabel.font = FONT(12);
    self.nickLabel = nickLabel;
    
    UILabel *numberLabel1 = [[UILabel alloc] init];
    [self.contentView addSubview:numberLabel1];
    [numberLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nickLabel.mas_right).offset(15);
        make.top.equalTo(nickLabel.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(30, 15));
    }];
    numberLabel1.textAlignment = NSTextAlignmentCenter;
    numberLabel1.textColor = BY_THEME_COLOR;
    numberLabel1.backgroundColor = rgba(248, 202, 188, 1);
    numberLabel1.font = FONT(8);
    self.numberLabel1 = numberLabel1;
    
    
    UIButton *bettingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:bettingBtn];
    [bettingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-15);
        make.centerY.equalTo(self.contentView).offset(0);
        make.size.mas_equalTo(CGSizeMake(66, 27));
    }];
    [bettingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [bettingBtn setTitle:@"立即跟单" forState:UIControlStateNormal];
    bettingBtn.backgroundColor = BY_THEME_COLOR;
    bettingBtn.titleLabel.font = FONT(12);
    bettingBtn.layer.cornerRadius = 5;
    [bettingBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
    self.bettingBtn = bettingBtn;
    
    UILabel *recordLabel = [[UILabel alloc] init];
    [self.contentView addSubview:recordLabel];
    [recordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nickLabel.mas_left).offset(0);
        make.centerY.equalTo(self.contentView).offset(5);
        make.size.mas_offset(CGSizeMake(65, 25));
    }];
    recordLabel.textColor = [UIColor lightGrayColor];
    recordLabel.text = @"100中10";
    recordLabel.textAlignment = NSTextAlignmentLeft;
    recordLabel.font = FONT(12);
    self.recordLabel = recordLabel;
    
    UILabel *notesLabel = [[UILabel alloc] init];
    [self.contentView addSubview:notesLabel];
    [notesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bettingBtn.mas_left).offset(-10);
        make.centerY.equalTo(recordLabel.mas_centerY).offset(0);
        make.left.equalTo(recordLabel.mas_right).offset(10);
        make.height.mas_equalTo(@15);
    }];
    notesLabel.font = FONT(12);
    notesLabel.text = @"预计回报";
    notesLabel.textColor = [UIColor lightGrayColor];
    notesLabel.textAlignment = NSTextAlignmentLeft;
    self.notesLabel = notesLabel;
    
    UILabel *moneyLabel = [[UILabel alloc] init];
    [self.contentView addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nickLabel.mas_left).offset(0);
        make.bottom.equalTo(iconView.mas_bottom).offset(5);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.mas_equalTo(@15);
    }];
    moneyLabel.font = FONT(12);
    moneyLabel.text = @"累计中奖100000元";
    moneyLabel.textColor = [UIColor lightGrayColor];
    self.moneyLabel = moneyLabel;
    
    UILabel *countLabel = [[UILabel alloc] init];
    [self.contentView addSubview:countLabel];
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-13);
        make.centerY.equalTo(bettingBtn.mas_top).offset(0);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    countLabel.backgroundColor = [UIColor whiteColor];
    countLabel.textAlignment = NSTextAlignmentCenter;
    countLabel.font = FONT(9);
    countLabel.textColor = BY_THEME_COLOR;
    countLabel.layer.borderColor = BY_THEME_COLOR.CGColor;
    countLabel.layer.borderWidth = 1;
    countLabel.layer.cornerRadius = 7.5;
    countLabel.layer.masksToBounds = YES;
    countLabel.text = @"5";
    self.countLabel = countLabel;
    
    
    
    
}

- (void)btnAction:(UIButton *)btn{
    
    if (self.betBlock) {
        self.betBlock();
    }
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:netModel.head_pic] placeholderImage:HEAD_ICOM_IMAGE];
     self.nickLabel.text = netModel.nickname;
    self.recordLabel.text = [NSString stringWithFormat:@"%@中%@",netModel.plan_num,netModel.hit_num];
    if (netModel.plan_count.integerValue > 0) {
        self.countLabel.text = [NSString stringWithFormat:@"%@",netModel.plan_count];
        self.bettingBtn.userInteractionEnabled = YES;
    }else{
        self.countLabel.hidden = YES;
        self.bettingBtn.backgroundColor = rgba(153, 153, 153, 1);
        self.bettingBtn.userInteractionEnabled = NO;
        [self.bettingBtn setTitle:@"不可跟单" forState:UIControlStateNormal];
        self.contentView.userInteractionEnabled = NO;
    }
    self.notesLabel.text = [NSString stringWithFormat:@"预计回报%@%%",netModel.rate_return];
    
    if (netModel.number.integerValue > 0) {
        self.numberLabel1.text = [NSString stringWithFormat:@"%@连中", netModel.number];
    }else{
        self.numberLabel1.hidden = YES;
    }
    
    
    self.moneyLabel.text = [NSString stringWithFormat:@"累计中奖%.2f元",netModel.plan_amount.floatValue];
    
}


@end
